public class MaxGap {
            public int findMaxGap(int[] A, int n) {
                if(A.length==0||n>A.length){
                    return 0;
                }
                int answer=0;
                int leftmax=0;
                for(int i=0;i<=n-2;i++){
                    if(leftmax<A[i]){
                        leftmax=A[i];
                    }
                    int rightmax=0;
                    for(int j=i+1;j<A.length;j++){
                        if(rightmax<A[j]){
                            rightmax=A[j];
                        }
                    }
                    int m=Math.abs(leftmax-rightmax);
                    if(m>answer){
                        answer=m;
                    }
                }
                return answer;
            }
        }
